function o(o) {
    return (o = o.toString())[1] ? o : "0" + o;
}

function t(o) {
    return o * Math.PI / 180;
}

var n = require("../meta");

module.exports = {
    getDistance: function(o, n, e, s) {
        var a = t(o), i = t(e), c = a - i, u = t(n) - t(s);
        return 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(c / 2), 2) + Math.cos(a) * Math.cos(i) * Math.pow(Math.sin(u / 2), 2))) * 6378137;
    },
    sendMessage: function(o, t, e, s) {
        o && "" != t && wx.request({
            url: n.url + "WXUsersForm?openid=" + o,
            header: {
                "Content-Type": "application/json",
                Authorization: "BasicAuth " + n.appid
            },
            success: function(a) {
                console.log("获取formid成功");
                var i = a.data;
                if ("" == i) return console.log("无可用的FORMID"), void wx.showModal({
                    title: "提示",
                    content: "无可用的FORMID，不能发送消息",
                    showCancel: !1
                });
                var c = {
                    touser: o,
                    template_id: t,
                    page: s,
                    form_id: i,
                    data: e,
                    color: "#ccc"
                }, u = {
                    appid: n.appid,
                    secret: n.secret,
                    data: c
                }, r = n.url + "WXUsersFormSend";
                wx.request({
                    url: r,
                    header: {
                        "Content-Type": "application/json",
                        Authorization: "BasicAuth " + n.appid
                    },
                    data: u,
                    method: "POST",
                    success: function(o) {
                        console.log("发送模板消息成功"), console.log(o);
                    },
                    fail: function(o) {
                        console.log("发送模板消息失败"), console.log(o);
                    }
                });
            },
            fail: function(o) {
                console.log("获取formid失败"), console.log(o);
            }
        });
    },
    formatTime: function(t) {
        var n = t.getFullYear(), e = t.getMonth() + 1, s = t.getDate(), a = t.getHours(), i = t.getMinutes(), c = t.getSeconds(), u = t.getMilliseconds();
        return [ n, e, s ].map(o).join("-") + "_" + [ a, i, c, u ].map(o).join("-");
    },
    _get: function(o, t, e) {
        console.log("------start---_get----"), wx.request({
            url: o,
            header: {
                "Content-Type": "application/json",
                Authorization: "BasicAuth " + n.appid
            },
            success: function(o) {
                t(o);
            },
            fail: function(o) {
                e(o);
            }
        }), console.log("----end-----_get----");
    },
    _put: function(o, t, e, s) {
        console.log("------start---_put----"), wx.request({
            url: o,
            header: {
                "Content-Type": "application/json",
                Authorization: "BasicAuth " + n.appid
            },
            method: "PUT",
            data: t,
            success: function(o) {
                e(o);
            },
            fail: function(o) {
                s(o);
            }
        }), console.log("----end-----_put----");
    },
    _post: function(o, t, e, s) {
        console.log("------start---_post----"), wx.request({
            url: o,
            header: {
                "Content-Type": "application/json",
                Authorization: "BasicAuth " + n.appid
            },
            method: "POST",
            data: t,
            success: function(o) {
                e(o);
            },
            fail: function(o) {
                s(o);
            }
        }), console.log("----end-----_post----");
    },
    _post_json: function(o, t, n, e) {
        console.log("------start---_post----"), wx.request({
            url: o,
            method: "POST",
            data: t,
            success: function(o) {
                n(o);
            },
            fail: function(o) {
                e(o);
            }
        }), console.log("----end----_post-----");
    }
};